import java.io.*;
import java.net.*;
import java.util.*;
import java.util.regex.*;

public class FindLinks {
	private String URL;
	private Pattern pattern;
	private List<String> pageContent;
	
	public Set<String> URLs;
	
	public FindLinks(String URL) {
		this.URL = URL;
		this.pattern = Pattern.compile("href=\\\"([^\\\"]+)\\\"");
		this.pageContent = new ArrayList<String>();
		this.URLs = new HashSet<String>();
		
		download();
	}
	
	public void findLinks() {
		for (String line : this.pageContent) {
			Matcher m = this.pattern.matcher(line);
			
			while (m.find()) {
				this.URLs.add(m.group(1));
			}
		}
	}
	
	private void download() {
		try {
			URL url = new URL(this.URL);
			InputStream is = url.openConnection().getInputStream();
			BufferedReader rdr = new BufferedReader(new InputStreamReader(is));
			String line;
			
			while ((line = rdr.readLine()) != null) {
				this.pageContent.add(line);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		if (args.length != 1) {
			System.err.println("Usage:  Visit <url>");
			System.exit(1);
		}
		
		String URL = args[0];
		FindLinks links = new FindLinks(URL);
		
		links.findLinks();
		
		for (String link : links.URLs) {
			System.out.println(link);
		}
	}
}
